<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>plugins</title>
  <script src="/vue.js"></script>
  <style>
    .btn {
      width: 100px;
      height: 40px;
      background: burlywood;
      text-align: center;
      line-height: 40px;
    }
  </style>
</head>
<body>
  <div id="root">
    <my-component></my-component>
    <div v-font:red>hello</div>
    <gp20-button title="按钮" color="red"></gp20-button>
  </div>
  <script>
    const myPlugin = {}

    myPlugin.install = (Vue, options) => {
      Vue.component('my-component', {
        template: `
          <div>my-component</div>
        `
      })
      Vue.component('gp20-button', {
        props: ['title', 'color'],
        template: `
          <div
            class="btn"
            :style={color}
          >{{title}}</div>
        `
      })
      Vue.filter('capital', (value) => {
        return value
      })
      Vue.directive('font', (el, bindings) => {
        let { arg } = bindings
        el.style.color = arg
      })
      Vue.mixin({
        // mounted() {
        //   console.log('mounted.')
        // },
      })
      Vue.prototype.$say = () => {
        console.log('hi')
      }
      Vue.prototype.$name = 'abc'
      Vue.print = (string) => {
        console.log(string)
      }
    }

    Vue.use(myPlugin)

    var vm = new Vue({
      el: '#root',
      mounted() {
        this.$say()
        console.log(this.$name)
        Vue.print('hello')
      }
    })
  </script>
</body>
</html>